package org.dtrd.modules.record.entity.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.common.util.CheckUtil;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninSugarValue;

import java.util.Date;

/**
 * 血糖值Bean
 *
 * @author xiao
 * @since 2021-10-09 17:31:46
 */
@ApiModel("血糖数据对象")
@Data
public class SugarValueBean implements java.io.Serializable {

    private static final long serialVersionUID = 6582995618567808945L;

    private Integer id;

    @ApiModelProperty("记录时间 yyyy-MM-dd HH:mm:ss")
    private String time;

    private String recordDate;

    @ApiModelProperty("血糖值")
    private Float value;

    private String remark;

    private Integer patientId;

    @ApiModelProperty("时间类型")
    private Integer type;

    private Integer sourceType;

    private Integer sugarValueType;

    private String recordPhoto;

    public SugarValueBean(Date time, float value, Constant.SugarRecordType type, Integer patientId) {
        this.time = DateUtils.formatDate(time, DateUtils.datetimeFormat.get().toPattern());
        this.value = value;
        this.type = type.getType();
        this.patientId = patientId;
    }

    public SugarValueBean(Float value, int type, int dataId, String photo) {
        this.value = value;
        this.type = type;
        this.id = dataId;
        if (CheckUtil.isNotEmpty(photo)) {
            this.recordPhoto = photo;
        }
    }

    public SugarValueBean() {
    }

    public SugarValueBean parseFromPo(DtrdEntRdSigninSugarValue po) {
        id = po.getDataId();
        if (po.getRecordTime() != null) {
            time = DateUtils.formatDateTime(po.getRecordTime());
            recordDate = DateUtils.formatDate(po.getRecordDate());
        }
        recordPhoto = po.getRecordPhoto();
        value = po.getSugarValueSugarValue();
        remark = po.getSugarValueRemark();
        patientId = po.getPatientId();
        type = po.getSugarValueTimeTypeId();
        sourceType = po.getSugarValueSourceType();
        sugarValueType = po.getSugarValueType();
        return this;
    }

    public SugarValueBean buildFromBloodSugar(BloodSugar sugar) {
        this.time = sugar.getBloodTimeStemp();
        this.value = sugar.getBloodSugar().floatValue();
        this.type = sugar.getSugarTimeType();
        this.remark = "雅培辅理善-瞬感伴侣";
        this.sourceType = Constant.SugarSourceType.SOURCE_SGBL_BLE.getType();
        return this;
    }
}